#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;
const int B = 131;
using ull = unsigned long long;

int n, m;
int a[N];
ull g[N], b[N];
map<int, int> pos;
int nxt[N];
bool cmp(pii a, pii b) {
  int len1 = a.second - a.first;
  int len2 = b.second - b.first;
  if (len1 != len2)
    return len1 < len2;
  else
    return a.first < b.first;
}
void solve() {
  cin >> n;
  rep(i, 1, n) cin >> a[i];
  g[n + 1] = 0, b[0] = 1;
  rep(i, 1, n) b[i] = b[i - 1] * B;
  per(i, n, 1) {
    nxt[i] = pos[a[i]];
    pos[a[i]] = i;
    g[i] = g[i + 1] * B + a[i];
  }
  vector<pii> ans;
  rep(i, 1, n) {
    int j = nxt[i];
    while (j > i && j * 2 <= n + 1 + i) {
      ull x = g[i] - g[j] * b[j - i];
      ull y = g[j] - g[j * 2 - i] * b[j - i];
      if (x == y) {
        ans.push_back(pii(i, j));
        break;
      }
      j = nxt[j];
    }
  }
  sort(ans.begin(), ans.end(), cmp);
  int l = 1;
  for (pii p : ans) {
    if (p.first < l) continue;
    l = p.second;
  }
  cout << n + 1 - l << endl;
  rep(i, l, n) cout << a[i] << ' ';
  return;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}